package com.itheima.fanshe;

import com.itheima.domain.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/*
获取构造方法对象  创建对象
 */
public class Demo07 {

    public static void main(String[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
        Class<Student> clazz = Student.class;
       // Student student = clazz.newInstance();
       /* Constructor<Student> constructor = clazz.getDeclaredConstructor();
       constructor.setAccessible(true);
               Student student = constructor.newInstance();*/
       /* Constructor<Student> constructor = clazz.getDeclaredConstructor(String.class);
        constructor.setAccessible(true);
        Student student = constructor.newInstance("坤坤");*/
        Constructor<Student> constructor = clazz.getDeclaredConstructor(String.class, int.class);
        Student student = constructor.newInstance("小鹿", 31);
        System.out.println(student);

    }
}
